package com.example.xwen.weight;

import java.text.DecimalFormat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class weight extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_weight);
        Bundle bundle = this.getIntent().getExtras();

        String sex = bundle.getString("sex");
        Double height = bundle.getDouble("height");

        String setText = "";
        if(sex.equals("male")){
            setText = "男性";
        }else{
            setText = "女性";
        }

        String weight = this.getWeight(sex,height);
        TextView t1 = (TextView) findViewById(R.id.t1);
        t1.setText("你的性别是"+setText+"\n你的身高为"+height+"cm\n你的标准体重是"+weight+"kg");
    }
    private String format(double num)
    {
        DecimalFormat df = new DecimalFormat("0.00");
        String s=df.format(num);
        return s;

    }

    private String getWeight(String sex,double height)
    {
        String weight="";
        if(sex.equals("male"))
        {
            weight=format((height-80)*0.7);
        }else
        {
            weight=format((height-70)*0.6);
        }
        return weight;
    }
}
